import moment from 'moment'
import { DBObject } from './DBObject'
import _ from 'lodash'
export enum UserSex {
    male = '男',
    female = '女'
}
export class User extends DBObject {
    public buyerName: string = ''
    public userName: string = ''
    public sex?: UserSex
    public birthday?: number
    public deathday?: number
    public address?: string
    public phone1: string = ''
    public phone2?: string
    public orders: string[] = []
    public remarks?: string
    public birthdayString: string
    public deathdayString: string
    constructor(user: any) {
        super(8);
        Object.assign(this, user);
        if (!this.orders) {
            this.orders = [];
        }
        this.birthdayString = this.birthday ? moment(this.birthday).format('YYYY-MM-DD') : '';
        this.deathdayString = this.deathday ? moment(this.deathday).format('YYYY-MM-DD') : '';
    }
    public addOrder(id: string) {
        this.orders.push(id);
    }
    public removeOrder(id: string) {
        if (this.orders instanceof Array) {
            if (this.orders.length > 0) {
                _.remove(this.orders, (item) => {
                    return item === id;
                })
            }
        }
    }
}